package Utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

public class FileUtils {

    public static void SaveFile(MultipartFile file) {
        if (file.isEmpty())
            return;

        try {
            File path = new File(GetSavePath() + "\\" + file.getOriginalFilename());
            file.transferTo(path);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static String GetSavePath() throws Exception
    {
        String basePath=System.getProperty("user.dir");
        File file=new File(basePath+"\\static");

        if(!file.exists())
            if(!file.mkdir())
                throw new Exception("文件夹创建失败");

        return System.getProperty("user.dir")+"\\static";
    }
}
